﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Twodi.Aspect.Implemented;
using Twodi.Aspect.Interfaces;

namespace Twodi.Implemented
{
    public abstract class AbstractManagedContainer<T> : AbstractContainer<T>
    {
        public AbstractManagedContainer(Game game)
            : base(game)
        {
            // Evento responsavel por mover todos componentes dentro do container caso o componente se mova.
            this.PositionProperties.PositionChanged += MoveChildrenComponents;
        }

        protected virtual void MoveChildrenComponents(object sender, Aspect.Args.PositionChangedEventArgs e)
        {
            for (int i = 0; i < Components.Count; i++)
            {
                IPositionAspect component = Components[i] as IPositionAspect;
                if (component != null)
                {
                    component.PositionProperties.Position += e.Difference;
                }
            }
        }
    }
}
